package com.example.tests;

import com.example.model.SortedListOf;
import com.example.model.TestBase;
import com.example.model.User;
import com.example.pages.UsersPage;
import org.junit.Test;

import static org.junit.Assert.assertEquals;


public class CreateNewUserTest extends TestBase {

    @Test
    public void addGuestUser() {

        UsersPage userPage = goToPage("/php4dvd/")
                .login("admin", "admin")
                .goToManagment();


        int oldSize = userPage.getUserCount();

        SortedListOf<User> oldUserList = userPage.getUsers();

        User user = new User()
                .withName("aaaaa").withEmail("useraa@mail.ru").withPassword("12345");

        if (oldUserList.contains(user)) {
            userPage.deleteUser(user);
            oldUserList = userPage.getUsers();
        }

        userPage.addGuestUser(user);

        int newSize = userPage.getUserCount();

        SortedListOf<User> newUserList = userPage.getUsers();

        assertEquals(newSize, oldSize + 1);
        assertEquals(newUserList, oldUserList.withAdded(user));
    }

    @Test
    public void testDeleteUser() throws Exception {
        goToPage("/php4dvd/")
                .login("admin", "admin")
                .goToManagment()
                .deleteUserGoodTest()
                .logout();
    }
}
